﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>BootStrap Table使用</title>
    <link href="~/css/bootstrap-table.css" rel="stylesheet" />
    <link href="~/css/bootstrap.css" rel="stylesheet" />
    <link href="~/css/ui-dialog.css" rel="stylesheet" />
    <link href="/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="~/css/labelauty.css" rel="stylesheet" />
    <script src="~/js/jquery.min.js"></script>
    <script src="~/js/bootstrap.js"></script>
    <script src="~/js/bootstrap-table.js"></script>
    <script src="~/js/bootstrap-table-zh-CN.js"></script>
    <script src="~/js/jquery.unobtrusive-ajax.js"></script>
    <script src="/js/content.min.js?v=1.0.0"></script>
    <script src="~/js/dialog-plus-min.js"></script>
    <script src="~/js/labelauty.js"></script>
    <script src="~/js/lsj/manager_role.js"></script>
</head>



<body>
    <div class="panel-body" style="padding-bottom:0px;">
        @using Web.helper;
        @{
            var actionName = ViewContext.RouteData.Values["action"].ToString().ToLower();
            var manager_id = User.Identity.Name;
        }
        @Html.Raw(Html.select_auth(manager_id, actionName))
        <table id="tb_departments"></table>
    </div>
    @using (Ajax.BeginForm("", new { }, new AjaxOptions() { HttpMethod = "Post", OnSuccess = "tips(data)", OnBegin = "ValidateLog" }))
    {
        <div class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="z-index:1000">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">新增</h4>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" name="id" class="form-control" id="id">
                        <div class="form-group">
                            <label for="txt_departmentname">角色名称</label>
                            <input type="text" name="txt_role_name" class="form-control" id="txt_role_name" placeholder="角色名称" required="">
                        </div>
                        <div class="form-group">
                            <label for="txt_departmentname">管理权限</label>
                            <input type="hidden" id="txt_action_type" name="txt_action_type" />
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <td>导航名称</td>
                                            <td>
                                                权限分配
                                            </td>
                                            <td>
                                                <!-- 多选 -->
                                                <div class="fuxuan">

                                                    <input type="checkbox" name="chk" class="chklist" />
                                                    <!--  -->
                                                    <label class="chkbox ckAlls">
                                                        <span class="check-image"></span>
                                                        <span class="radiobox-content">全选</span>
                                                    </label>
                                                    <!--  -->
                                                </div>
                                            </td>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        @{                                            
                                            foreach (var nav in ViewBag.list_nav)
	                                        {
		                                    <tr>
                                            <th class="text-nowrap">@if(nav.parent_id != 0){<i class="fa fa-folder-open"></i>}  @nav.title</th>
                                            <td>
                                                <!-- 多选 -->
                                                <div class="fuxuan">
                                                    @foreach (var item in nav.action_type.Split(new char[] { ',' }))
                                                    {
                                                         <input type="checkbox" name="chk" class="chklist" />
                                                            <!--  -->
                                                            <label id="@nav.id" class="chkbox">
                                                                <span class="check-image"></span>
                                                                <span class="radiobox-content">@item</span>
                                                            </label>
                                                    }
                                                </div>
                                            </td>
                                            <td>
                                                <!-- 多选 -->
                                                <div class="fuxuan">

                                                    <input type="checkbox" name="chk" class="chklist" />
                                                    <!--  -->
                                                    <label class="chkbox ckAll">
                                                        <span class="check-image"></span>
                                                        <span class="radiobox-content">全选</span>
                                                    </label>
                                                    <!--  -->
                                                </div>
                                            </td>
                                        </tr>
	                                        }
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                        <button class="btn btn-primary block full-width m-b" id="btn_submit" onclick="onck()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                    </div>
                </div>
            </div>
        </div>
    }
</body>
</html>
<script>
    $(document).ready(function () {
        //参数{input类名，选择类型(单选or多选)}
        $(".rdolist").labelauty("rdolist", "rdo");
        $(".chklist").labelauty("chklist", "check");

        //单行全选
        $(".ckAll").click(function ()
        {
            var t = $(this);
            $(this).parent().parent().prev().find(".chkbox").each(function ()
            {
                if ($(t).prev().prop("checked")) {
                    $(this).prev().prop("checked", "checked");
                    $(this).removeClass("unchecked");
                    $(this).addClass("checked");
                    $(this).children(".check-image").css("background", "url(../img/input-checked.png)");
                } else
                {
                    $(this).prev().prop("checked", "");
                    $(this).removeClass("checked");
                    $(this).addClass("unchecked");
                    $(this).children(".check-image").css("background", "url(../img/input-unchecked.png)");
                }
            })

        })

        //所有全选
        $(".ckAlls").click(function ()
        {
            var t = $(this);
            $(".table-responsive table tbody tr td .chkbox").each(function ()
            {
                if ($(t).prev().prop("checked")) {
                    $(this).prev().prop("checked", "checked");
                    $(this).removeClass("unchecked");
                    $(this).addClass("checked");
                    $(this).children(".check-image").css("background", "url(../img/input-checked.png)");
                } else
                {
                    $(this).prev().prop("checked", "");
                    $(this).removeClass("checked");
                    $(this).addClass("unchecked");
                    $(this).children(".check-image").css("background", "url(../img/input-unchecked.png)");
                }
            })
        })


    });
    function onck() {
        //选中权限
        //格式: 1:查看,修改;2:删除,修改,审核;6:;
        var action_type = "";
        $(".table-responsive table tbody").find("tr").each(function () {
            var t = $(this).find("td").eq(0).find(".chkbox");
            action_type += $(t).attr("id") + ":";
            $(t).each(function () {
                if ($(this).prev().prop("checked")) {
                    action_type += $(this).children(".radiobox-content").html() + ","
                }
            })

            if (action_type.charAt(action_type.length - 1) == ",") {
                action_type = action_type.substring(0, action_type.length - 1);
            }
            action_type += ";";
        })
        $("#txt_action_type").val(action_type);
    }


    //登录前js验证
    function ValidateLog() {
       
    }


    //登录回调函数
    function tips(data) {
        var d = dialog({
            padding: 30,
            content: data.msg
        });

        if (data.status == 0) {
            //添加成功

            //显示模态框
            d.show();
            //先关闭主窗体
            $('#myModal').modal('hide')
            //刷新数据
            $('#tb_departments').bootstrapTable('refresh', { url: '/Templet/GetManager_roleList' });
            //关闭提示模态框
            setTimeout(function () {
                d.close().remove();
            }, 2000);
        } else if (data.pitchId != "") {
            point(data.pitchId, data.msg);
        } else {
            //添加失败
            d = dialog({
                padding:30,
                content: data.msg
            });
            //关闭提示模态框
            setTimeout(function () {
                d.close().remove();
            }, 2000);
        }
    }

    //输出提示信息
    function point(id,content)
    {
        var follow = document.getElementById(id);
        var d = dialog({
            align: 'bottom',
            content: '<span class="label label-warning">!</span> ' + content
        });
        d.show(follow);
        setTimeout(function () {
            d.close().remove();
        }, 2000);
    }

</script>